# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=gimp

pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.8.10
pkgrel=7
pkgdesc="GNU Image Manipulation Program (mingw-w64)"
arch=('any')
groups=("${MINGW_PACKAGE_PREFIX}")
url="http://www.gimp.org/"
license=('GPL' 'LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-python2-pygtk"
        "${MINGW_PACKAGE_PREFIX}-lcms2"
        "${MINGW_PACKAGE_PREFIX}-xpm-nox"
        "${MINGW_PACKAGE_PREFIX}-libwmf"
        "${MINGW_PACKAGE_PREFIX}-librsvg"
        "${MINGW_PACKAGE_PREFIX}-libmng"
        "${MINGW_PACKAGE_PREFIX}-dbus-glib"
        "${MINGW_PACKAGE_PREFIX}-libexif"
        "${MINGW_PACKAGE_PREFIX}-gegl"
        "${MINGW_PACKAGE_PREFIX}-jasper"
        "${MINGW_PACKAGE_PREFIX}-hicolor-icon-theme"
        "${MINGW_PACKAGE_PREFIX}-babl"
        "${MINGW_PACKAGE_PREFIX}-openexr"
        "${MINGW_PACKAGE_PREFIX}-webkitgtk2"
        "${MINGW_PACKAGE_PREFIX}-poppler"
        "${MINGW_PACKAGE_PREFIX}-curl"
        "${MINGW_PACKAGE_PREFIX}-ghostscript"
        )
makedepends=('intltool'
            "${MINGW_PACKAGE_PREFIX}-iso-codes"
            "${MINGW_PACKAGE_PREFIX}-curl"
            "${MINGW_PACKAGE_PREFIX}-webkitgtk2"
            "${MINGW_PACKAGE_PREFIX}-poppler"
            "${MINGW_PACKAGE_PREFIX}-ghostscript")
options=('strip' 'makeflags')
install=gimp-${CARCH}.install
source=(http://download.gimp.org/pub/gimp/v${pkgver%.*}/${_realname}-${pkgver}.tar.bz2{,.md5} 
        uri-backend-libcurl.patch
        patch_CVE197.patch
        patch_CVE1913.patch
        freetype_location.patch
        gegl-0.3-fix.patch
        find-directx-fix.patch
        python-m4.patch
        mingw-add-ModuleFileName-dir-to-PATH.patch)
md5sums=('84c964aab7044489af69f7319bb59b47'
         'c80070bf99005917b0d35263bfedc3f2'
         'e894f4b2ffa92c71448fdd350e9b78c6'
         '901643efc82fae57af466d8a0a8991ff'
         'dcc2acc9f9962a7c83ffb4243c08c469'
         'ca0f32cb329ddad8079f8e2c0fc75b29'
         'd1e19159164cac7b39578a6b0bb02cbb'
         '0df0c9c5f55012023894ed8b959c2fa9'
         '34aba5cb94d368627bf17eb5aedee556'
         '0d5c523e91fbfbab43c2f12447ccfebc')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  #patch -p1 -i ${srcdir}/uri-backend-libcurl.patch
  patch -p1 -i ${srcdir}/patch_CVE1913.patch
  patch -p1 -i ${srcdir}/patch_CVE197.patch
  patch -p1 -i ${srcdir}/freetype_location.patch
  patch -p1 -i ${srcdir}/gegl-0.3-fix.patch
  patch -p1 -i ${srcdir}/find-directx-fix.patch
  patch -p1 -i ${srcdir}/python-m4.patch
  patch -p1 -i ${srcdir}/mingw-add-ModuleFileName-dir-to-PATH.patch
  
  rm -fr autom4te.cache
  libtoolize -c
  aclocal -I m4macros
  automake -a -c
  autoheader
  autoconf

  #autoreconf -fi -I m4macros
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  CPPFLAGS+=" -I${MINGW_PREFIX}/include/noX"
  CFLAGS+=" -D__USE_MINGW_ANSI_STDIO=1 -I${MINGW_PREFIX}/include/noX"
  CXXFLAGS+=" -D__USE_MINGW_ANSI_STDIO=1 -I${MINGW_PREFIX}/include/noX"
  PYTHON=${MINGW_PREFIX}/bin/python2 \
  ./configure --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --sysconfdir=${MINGW_PREFIX}/etc \
    --enable-mp \
    --enable-gimp-console \
    --enable-python \
    --with-gif-compression=lzw \
    --with-libcurl \
    --without-aa \
    --with-lcms=lcms2 \
    --with-pdbgen \
    --with-directx-sdk=${MINGW_PREFIX}/${MINGW_CHOST} \
    --without-x
  make
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  make DESTDIR="${pkgdir}" install

  ln -s gimptool-2.0 "${pkgdir}${MINGW_PREFIX}/bin/gimptool.exe"
  cp ${pkgdir}${MINGW_PREFIX}/lib/gimp/2.0/{plug-ins,python}/pyconsole.py
  sed -e "s|${MINGW_PREFIX}/bin/python2|python2w.exe|g" -i ${pkgdir}${MINGW_PREFIX}/lib/gimp/2.0/interpreters/pygimp.interp
  rm -f "${pkgdir}${MINGW_PREFIX}/lib/*.def"
  rm -f "${pkgdir}${MINGW_PREFIX}/lib/gimp/2.0/modules/*.dll.a"
}
